import { 
  HTTP 
} from "../utils/http.js"
class KeywordModel extends HTTP {
  key = 'f'
  maxLength = 10
  getHistory() {
    const words = wx.getStorageSync(this.key)
    if (!words) {
      return []
    }
    return words
  }
  getHot(resolve) {
    this.request({
      url:'book/hot_keyword',
      success: (res)=>{
        resolve(res)
      }
    })
  }
  addToHistory(keyWord) {
    let words = this.getHistory()
    const hasWord = words.includes(keyWord)
    if (!hasWord) {
      if (words.length > this.maxLength) {
        words.pop()
      }
      words.unshift(keyWord)
      wx.setStorageSync(this.key, words)
    }
  }

  

}

export {
  KeywordModel
}
